
package com.kugou.game.sdk.ui.dialog;

import com.kugou.framework.base.BaseDialog;
import com.kugou.game.sdk.utils.Rx;

import android.app.Activity;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

public class CanAddContentViewDialog extends BaseDialog {

    private Activity activity;

    private TextView tvTitle;

    private ImageButton imageButtonDismiss;

    private LinearLayout layoutContent;

    private Button btnSure, btnCancel;

    public CanAddContentViewDialog(Activity activity, int theme) {
        super(activity, theme);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        this.activity = activity;
        initView();
    }

    public CanAddContentViewDialog(Activity activity) {
        this(activity, 0);
    }

    private void initView() {
        int layoutId = Rx.layout.kg_can_add_content_view_dialog;
        setContentView(layoutId);
    }

    @Override
    public void onContentChanged() {
        super.onContentChanged();
        tvTitle = (TextView) findViewById(Rx.id.kg_common_dialog_title);
        imageButtonDismiss = (ImageButton) findViewById(Rx.id.kg_common_dialog_button);
        layoutContent = (LinearLayout) findViewById(Rx.id.kg_layout_content);
        btnSure = (Button) findViewById(Rx.id.kg_btn_sure);
        btnCancel = (Button) findViewById(Rx.id.kg_btn_cancel);
        btnCancel.setOnClickListener(mCancelClickListener);
        imageButtonDismiss.setOnClickListener(mCancelClickListener);
    }

    public void addContentView(View view) {
        if (view != null) {
            layoutContent.setVisibility(View.VISIBLE);
            layoutContent.addView(view);
        }
    }

    public void removeAllContentView() {
        layoutContent.setVisibility(View.GONE);
        layoutContent.removeAllViews();
    }

    /**
     * 设置标题
     * 
     * @param mTitle 标题
     */
    public void setCommonTitle(final String title) {
        if (tvTitle != null) {
            tvTitle.setText(title);
        }
    }

    /**
     * 设置标题
     * 
     * @param strResId 字符串id
     */
    public void setCommonTitle(int strResId) {
        if (tvTitle != null) {
            tvTitle.setText(strResId);
        }
    }

    private View.OnClickListener mCancelClickListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    };

    public void setSureClickListener(View.OnClickListener listener) {
        btnSure.setOnClickListener(listener);
    }

    public void setCancelClickListener(View.OnClickListener listener) {
        btnCancel.setOnClickListener(listener);
    }

    /**
     * 设置取消按钮名称
     */
    public void setCancelText(String str) {
        btnCancel.setText(str);
    }

    /**
     * 设置ok按钮名称
     */
    public void setSureBtnText(String str) {
        btnSure.setText(str);
    }
}
